
import com.aaron.platform.common.BeanUtils;
import com.aaron.platform.common.PrevilegeVisitor;
import com.aaron.platform.dao.IXmlParser;
import com.aaron.platform.dao.XmlParserImp;
import com.aaron.platform.exceptions.XmlParseException;
import com.aaron.platform.exceptions.XmlPathException;
import com.aaron.platform.entity.ItscPriExt;
import com.aaron.platform.entity.ItscPriInfo;
import com.aaron.platform.entity.ItscRoleInfo;
import com.aaron.platform.entity.ItscUserInfo;
import com.aaron.platform.service.AuthoritySeviceImp;
import com.aaron.platform.service.IAuthorityService;
import java.io.File;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.omg.CORBA.INITIALIZE;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author chenzhuohua
 */
public class XMlTest {

    XMlTest() {

        File file = new File("src/java/student.xml");
        System.out.println(file.getAbsolutePath());

        IXmlParser xmlParser = new XmlParserImp();
        try {
            List<ItscPriInfo> itscPreInfos = xmlParser.parsePreInfoXml(file);
            for (ItscPriInfo itscPreInfo : itscPreInfos) {
                System.out.println("PreInfo name:" + itscPreInfo.getPrivilegeName());
                System.out.println("PreInfo disName:" + itscPreInfo.getPrivilegeDisname());
                System.out.println("PreInfo desc:" + itscPreInfo.getPrivilegeDesc());
                for (ItscPriExt ext : itscPreInfo.getItscPriExtList()) {
                    System.out.println("--PreExt name:" + ext.getOperName());
                    System.out.println("--PreExt disname:" + ext.getOperDisname());
                    System.out.println("--PreExt value" + ext.getOperValue());
                }
            }
        } catch (XmlPathException ex) {
            Logger.getLogger(XMlTest.class.getName()).log(Level.SEVERE, null, ex);
        } catch (XmlParseException ex) {
            Logger.getLogger(XMlTest.class.getName()).log(Level.SEVERE, null, ex);
        }

        System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));

        System.out.println(XMlTest.class.getClassLoader().getResource(""));

        System.out.println(ClassLoader.getSystemResource(""));
        System.out.println(XMlTest.class.getResource(""));
        System.out.println(XMlTest.class.getResource("/")); //Class文件所在路径
        System.out.println(new File("/").getAbsolutePath());
        System.out.println(System.getProperty("user.dir") + File.separator + "a.xml");
    }

    public static void main(String[] args) {
        //new XMlTest();
        //init();\
        testBeanUtil();
    }

    private static void init() {
        IXmlParser xmlParser = new XmlParserImp();
        AuthoritySeviceImp authorityService = new AuthoritySeviceImp();
        authorityService.setXmlParser(xmlParser);
        ItscUserInfo userInfo = new ItscUserInfo();
        ItscRoleInfo roleInfo = new ItscRoleInfo(1);
        userInfo.setRoleInfo(roleInfo);
        try {
            authorityService.init();
            boolean bPri = false;
            boolean bPriExt = false;
            bPri = authorityService.hasPrivilege(userInfo, "p1");
            bPriExt = authorityService.hasExtPrivilege(userInfo, "p1", "view");
            System.out.println(bPri);
            System.out.println(bPriExt);

        } catch (XmlPathException ex) {
            Logger.getLogger(XMlTest.class.getName()).log(Level.SEVERE, null, ex);
        } catch (XmlParseException ex) {
            Logger.getLogger(XMlTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private static void testBeanUtil() {
        ItscPriInfo priInfo = new ItscPriInfo("aa");
        priInfo.setPrivilegeDisname("AA");
        ItscPriExt priExt = new ItscPriExt("bb");
        priExt.setOperDisname("BB");
        priExt.setOperValue(1);
        priExt.setEnabled(true);
        ItscPriExt priExt1 = new ItscPriExt("bb");
        priExt1.setOperDisname("BB");
        priExt1.setOperValue(1);
        priExt1.setEnabled(true);

        priInfo.addPriExt(priExt);
        priInfo.addPriExt(priExt1);

        ItscPriInfo priInfo1 = (ItscPriInfo) BeanUtils.objectClone(priInfo);

        System.out.println(priInfo);
        System.out.println(priInfo1);
    }
}
